/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.model.CodeRule;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class CodeRuleValidator implements Validator {
	public boolean supports(Class clazz) {
		return CodeRule.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		CodeRule form = (CodeRule) obj;
		boolean hasError = false;
		if (!form.getGenerateRule().equals("MANUAL")
				&& !form.getGenerateRule().equals("AUTO_TYPE_CODE")
				&& (form.getPrefix() == null || form.getPrefix().trim()
						.equals(""))) {
			errors.rejectValue("prefix", "", "请输入『前缀』");
			hasError = true;
		}

		if (!hasError && form.getPrintFoot() != null
				&& form.getPrintFoot().length() >= 500) {
			errors.rejectValue("printFoot", "", "『打印页脚』不能超过500个字符");
			hasError = true;
		}

	}
}